package pattern.memento.black;

import lombok.AllArgsConstructor;
import lombok.Data;

// 游戏角色类
@Data
public class GameRole {
    // 生命力
    private Integer vit;
    // 攻击力
    private Integer atk;
    // 防御力
    private Integer def;

    /**
     * 初始化状态
     */
    public void init() {
        this.vit = 100;
        this.atk = 100;
        this.def = 100;
    }
    // 战斗力到0
    public void fight() {
        this.vit = 0;
        this.atk = 0;
        this.def = 0;
    }

    // 保存角色状态
    public RoleStateMemento saveState() {
        return new RoleStateMemento(this.vit, this.atk, this.def);
    }
    // 恢复角色状态
    public void recoverState(Memento memento) {
        RoleStateMemento roleStateMemento = (RoleStateMemento) memento;
        this.vit = roleStateMemento.getVit();
        this.atk = roleStateMemento.getAtk();
        this.def = roleStateMemento.getDef();
    }

    // 展示状态
    public void showState() {
        System.out.println("角色生命力：" + this.vit);
        System.out.println("角色攻击力：" + this.atk);
        System.out.println("角色防御力：" + this.def);
    }

    // 备忘录内部类
    @Data
    @AllArgsConstructor
    private class RoleStateMemento implements Memento {
        // 生命力
        private Integer vit;
        // 攻击力
        private Integer atk;
        // 防御力
        private Integer def;
    }
}
